<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
          <el-col :span="8">
              <el-form-item label="关键字" prop="phonenumber" style="width: 90%;">
                  <el-input
                  v-model="queryParams.phonenumber"
                  placeholder="请输入关键字"
                  clearable
                  @keyup.enter="handleQuery"
                  />
              </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单时间" style="width: 90%;">
              <el-date-picker
                  v-model="dateRange"
                  value-format="YYYY-MM-DD"
                  type="daterange"
                  range-separator="-"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button type="danger" icon="Search" @click="handleQuery" v-hasPermi="['partybuilding:MallOrder:query']">查询</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-col>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="goodsOrderList" @selection-change="handleSelectionChange">
      <el-table-column label="用户名称" align="left" prop="userNickname" width="150"/>
      <el-table-column label="订单编号" align="left" prop="orderNum" width="210"/>
      <el-table-column label="订单时间" align="left" prop="createTime" width="200"/>
      <el-table-column label="兑换商品名称" align="left" prop="goodsName" min-width="200" show-overflow-tooltip="true"/>
      <el-table-column label="兑换数量" align="left" prop="quantity" width="150"/>
      <el-table-column label="消耗积分数" align="left" prop="totalPrice" width="150"/>
      <el-table-column label="手机号码" align="left" prop="phonenumber" width="150"/>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="GoodsOrder">
import { listMallOrder, getMallOrder, addMallOrder } from "@/api/mall/GoodsOrder";
const { proxy } = getCurrentInstance();
const goodsOrderList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const dateRange = ref([]);
const orderStatusOptions = ref([{value: '0', label: '待确认'},{value: '1', label: '已完成'}]);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    phonenumber: "",
    status: null
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询商品订单列表 */
function getList() {
  if (dateRange!=null && dateRange.value.length > 0) {
    queryParams.value.createTime = dateRange.value[0]+" 00:00:00";
    queryParams.value.createTime2 = dateRange.value[1]+" 23:59:59";
  }
  loading.value = true;
  listMallOrder(queryParams.value).then(response => {
    goodsOrderList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
